package cn.iocoder.yudao.module.crossborder.crm.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.crm.api.dto.CustomerDTO;
import cn.iocoder.yudao.module.crossborder.crm.service.CrmService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 客户关系管理 API 接口实现类
 *
 * @author LHL
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class CrmApiImpl implements CrmApi {

    @Resource
    private CrmService crmService;

    @Override
    public CommonResult<CustomerDTO> getCustomer(Long id) {
        CustomerDTO customer = crmService.getCustomer(id);
        return success(customer);
    }

    @Override
    public CommonResult<List<CustomerDTO>> getCustomerList(List<Long> ids) {
        List<CustomerDTO> customers = crmService.getCustomerList(ids);
        return success(customers);
    }

    @Override
    public CommonResult<Long> createCustomer(CustomerDTO customer) {
        Long id = crmService.createCustomer(customer);
        return success(id);
    }

    @Override
    public CommonResult<Boolean> validateCustomer(Long customerId) {
        Boolean exists = crmService.validateCustomer(customerId);
        return success(exists);
    }

    @Override
    public CommonResult<List<CustomerDTO>> searchCustomers(String keyword) {
        List<CustomerDTO> customers = crmService.searchCustomers(keyword);
        return success(customers);
    }

}
